﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data.OleDb;

namespace WebSite_CodeMan.BLL
{
    public class WebInfo
    {
        /// <summary>
        /// 修改密码
        /// </summary>BaseClass.BaseClass.PassEnCode(strOldPass)
        /// <param name="strOldPass"></param>
        /// <param name="strNewPass"></param>
        /// <returns></returns>
        public static bool VateUpdatePass(string strOldPass, string strNewPass)
        {
            try
            {
                OleDbParameter[] parm = {new OleDbParameter("@NewPass",BaseClass.BaseClass.PassEnCode(strNewPass)),
                                         new OleDbParameter("@OldPass",BaseClass.BaseClass.PassEnCode(strOldPass))};
                return (DBUnlity.AccessHelper.ExecuteNonQuery(DBUnlity.AccessHelper.ConnectionString, " UPDATE T_Web_BaseInfo SET T_ManagePassWord=@NewPass WHERE T_ManagePassWord=@OldPass ", parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 检测用户登录的用户名和密码
        /// </summary>
        /// <param name="strUserPass"></param>
        /// <returns></returns>
        public static bool CheckUserLogin(string strUserPass)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_ManageName", Common.GetMes.GetConfigAppValue("AdminName")),
                                          new OleDbParameter("@NewPass", BaseClass.BaseClass.PassEnCode(strUserPass)) };
                string strRe = DBUnlity.AccessHelper.ExecuteScalar(DBUnlity.AccessHelper.ConnectionString, " SELECT COUNT(*) FROM T_Web_BaseInfo WHERE  T_ManageName=@T_ManageName AND T_ManagePassWord=@NewPass ", parm).ToString();
                LogInfo.AddSysLog("【" + Common.GetMes.GetConfigAppValue("AdminName") + "】于{" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "}。登录后台。—" + ((strRe != "0") ? "【成功】" : "【失败】"));
                return (strRe == "0") ? false : true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取提示信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static string[] GetSysSPInfo()
        {
            try
            {
                string[] strSql = { " SELECT COUNT(*) FROM T_Leave_Info WHERE T_Flag=0 ",
                                    " SELECT COUNT(*) FROM T_Note_Info  ",
                                    "  SELECT COUNT(*) FROM T_Note_Info  WHERE Remark is null or Remark='' and  T_NoteClassID<>'' "};
                string[] strRe = new string[3];
                for (int i = 0; i < strSql.Length; i++)
                {
                    strRe[i] = DBUnlity.AccessHelper.ExecuteScalar(DBUnlity.AccessHelper.ConnectionString, strSql[i], null).ToString();

                }
                return strRe;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取网站基本信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static OleDbDataReader GetWebBaseInfo()
        {
            try
            {
                return DBUnlity.AccessHelper.ExecuteReader(DBUnlity.AccessHelper.ConnectionString, " SELECT T_WebName,T_WebLink,T_WebNumber,T_WebKey,T_WebDes,T_WebWord,T_WebSkin,T_SPSSMes FROM T_Web_BaseInfo ", null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 获取网站模板路劲信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static string GetWebTemplateInfo()
        {
            try
            {
                return DBUnlity.AccessHelper.ExecuteScalar(DBUnlity.AccessHelper.ConnectionString, " SELECT T_WebSkin FROM T_Web_BaseInfo ", null).ToString();
            }
            catch
            {
                return "Default";
            }
        }
        /// <summary>
        /// 获取网站简介信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static string GetWebAboutInfo()
        {
            try
            {
                return DBUnlity.AccessHelper.ExecuteScalar(DBUnlity.AccessHelper.ConnectionString, " SELECT T_WebAbout FROM T_Web_BaseInfo ", null).ToString();
            }
            catch
            {
                return "";
            }
        }
        /// <summary>
        /// 更新网站简介信息 
        /// </summary>
        /// <param name="strClass"></param>
        /// <returns></returns>
        public static bool UpdateWebAboutInfo(string strAbout)
        {
            try
            {
                return (DBUnlity.AccessHelper.ExecuteNonQuery(DBUnlity.AccessHelper.ConnectionString, string.Format(" UPDATE T_Web_BaseInfo SET T_WebAbout='{0}'", strAbout), null) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 更新网站基本信息
        /// </summary>
        /// <returns></returns>
        public static bool UpdateWebInfo(string T_WebName, string T_WebLink, string T_WebKey, string T_WebNumber, string T_WebDes, string T_WebWord, string T_WebSkin, string T_SPSSMes)
        {
            try
            {
                OleDbParameter[] parm = { new OleDbParameter("@T_WebName", T_WebName),
                                      new OleDbParameter("@T_WebLink", T_WebLink),
                                      new OleDbParameter("@T_WebNumber", T_WebNumber),
                                      new OleDbParameter("@T_WebKey", T_WebKey),
                                      new OleDbParameter("@T_WebDes", T_WebDes),
                                      new OleDbParameter("@T_WebWord", T_WebWord),
                                      new OleDbParameter("@T_WebSkin", T_WebSkin),
                                      new OleDbParameter("@T_SPSSMes", T_SPSSMes)};
                string strSql = "UPDATE T_Web_BaseInfo SET T_WebName=@T_WebName,T_WebLink=@T_WebLink,T_WebNumber=@T_WebNumber,T_WebKey=@T_WebKey,T_WebDes=@T_WebDes,T_WebWord=@T_WebWord,T_WebSkin=@T_WebSkin,T_SPSSMes=@T_SPSSMes";
                return (DBUnlity.AccessHelper.ExecuteNonQuery(DBUnlity.AccessHelper.ConnectionString, strSql, parm) > 0) ? true : false;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        /// <summary>
        /// 获取网站基本信息---用于生成静态页 
        /// </summary>
        /// <param name="strType">字段类型</param>
        /// <returns></returns>
        public static OleDbDataReader GetWebBaseInfo(string strType)
        {
            try
            {
                string strSql = string.Empty;
                switch (strType)
                {
                    case "1":
                        strSql = " SELECT T_WebName,T_WebWord,T_WebSkin ";
                        break;
                    case "2":
                        strSql = " SELECT T_WebLink,T_WebNumber,T_SPSSMes ";
                        break;
                    case "3":
                        strSql = " SELECT  T_WebAbout ";
                        break;
                    case "4":
                        strSql = " SELECT  T_WebName,T_WebKey,T_WebDes,T_WebSkin  ";
                        break;
                    case "5":
                        strSql = " SELECT  T_WebName,T_WebKey,T_WebDes,T_WebLink,T_WebNumber,T_WebWord,T_SPSSMes  ";
                        break;
                    default:
                        strSql = " SELECT * ";
                        break;
                }
                strSql += " FROM T_Web_BaseInfo  ";
                return DBUnlity.AccessHelper.ExecuteReader(DBUnlity.AccessHelper.ConnectionString, strSql, null);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
